package br.ufrn.engcomp.domain;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Transient;

import br.ufrn.engcomp.arq.PersistDB;

/**
 * Representa um experimento no sistema.
 * 
 * @author Victor Carvalho Galvao de Freitas
 * 
 */
@Entity
public class Experiment implements PersistDB {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "experiment_seq")
    @SequenceGenerator(name = "experiment_seq", sequenceName = "id_experiment", allocationSize = 0)
    private int id;

    private String name;

    @ManyToOne
    @JoinColumn(name = "userr_id")
    private User userr;

    private Double setPoint;

    @OneToMany(cascade = CascadeType.ALL)
    private Collection<DadosExperimento> data;

    @OneToOne(cascade = CascadeType.ALL)
    private PIDController pidController;

    @OneToOne(cascade = CascadeType.ALL)
    private ManualController manualController;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    private Collection<TimeSlot> timeSlots;

    @Transient
    private Integer numSlotsReservados;
//    private Integer numSlotsReservados = new Integer(0);

    @Transient
    private double tempo = 0.0;

    public Experiment() {
	manualController = new ManualController();
	pidController = new PIDController();
	numSlotsReservados = new Integer(0);
	timeSlots = new ArrayList<TimeSlot>();
    }

    public int getId() {
	return id;
    }

    public void setId(int id) {
	this.id = id;
    }

    public double getTempo() {
	return tempo;
    }

    public void setTempo(double tempo) {
	this.tempo = tempo;
    }

    public User getUserr() {
	return userr;
    }

    public void setUserr(User userr) {
	this.userr = userr;
    }

    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    public Collection<DadosExperimento> getData() {
	return data;
    }

    public void setData(Collection<DadosExperimento> data) {
	this.data = data;
    }

    public Double getSetPoint() {
	return setPoint;
    }

    public void setSetPoint(Double setPoint) {
	this.setPoint = setPoint;
    }

    public Collection<TimeSlot> getTimeSlots() {
	return timeSlots;
    }

    public void setTimeSlots(Collection<TimeSlot> timeSlots) {
	this.timeSlots = timeSlots;
    }

    public Integer getNumSlotsReservados() {
	return numSlotsReservados;
    }

    public void setNumSlotsReservados(Integer numSlotsReservados) {
	this.numSlotsReservados = numSlotsReservados;
    }

    public PIDController getPidController() {
	return pidController;
    }

    public void setPidController(PIDController pidController) {
	this.pidController = pidController;
    }

    public ManualController getManualController() {
	return manualController;
    }

    public void setManualController(ManualController manualController) {
	this.manualController = manualController;
    }

}
